<?php
/*
This file is part of TEXTLOG.

TEXTLOG is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

TEXTLOG is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with TEXTLOG. If not, see http://www.gnu.org/licenses/.
*/

function textlog_globalnav() {
	if ( $menu = str_replace( array( "\r", "\n", "\t" ), '', wp_list_pages('title_li=&sort_column=menu_order&exclude=60,179&echo=0') ) )
		$menu = '<ul>' . $menu . '</ul>';
	$menu = '<div id="menu">' . $menu . "</div>\n";
	echo $menu;
}

// Echos the theme template style sheet links with absolute URIs
function textlog_css() {
	$cssdir = get_bloginfo('stylesheet_directory') . '/css';
	$css  = "\t" . '<link rel="stylesheet" type="text/css" href="' . $cssdir . '/main.css" media="screen,projection" />' . "\n";
	$css .= "\t" . '<link rel="stylesheet" type="text/css" href="' . $cssdir . '/print.css" media="print" />' . "\n";
	echo $css;
}

// Echos the JavaScript with absolute URIs
function textlog_js() {
	$textareaId = null;
	$jsdir = get_bloginfo('stylesheet_directory') . '/js';
	$js = '<script type="text/javascript" src="' . $jsdir . '/jquery.pack.js"></script>' . "\n";
	if ( is_page('contact') ) {
		$js .= '<script type="text/javascript" src="' . $jsdir . '/pretty-comments.pack.js"></script>' . "\n";
		$textareaId = "\n\t" . 'prettyComments.init("ec_message");';
	} elseif ( is_single() ) {
		$js .= '<script type="text/javascript" src="' . $jsdir . '/pretty-comments.pack.js"></script>' . "\n";
		$textareaId = "\n\t" . 'prettyComments.init("comment");';
	}
	$js .= '<script type="text/javascript" charset="' . get_bloginfo('charset') . '">
// <![CDATA[
$(document).ready(function(){
	var syntaxHighlight = false;
	$("div#menu ul li").hover(function(){$("ul",this).fadeIn("fast");},function(){});
	if(document.all){$("div#menu ul li").hoverClass("sfHover");}
	$("div#content pre").each(function(){$(this).addClass("prettyprint");syntaxHighlight = true;});
	if(syntaxHighlight){$.getScript("' . $jsdir . '/prettify.pack.js",function(){prettyPrint()});}
});';
	$js .= $textareaId;
	$js .= "\n" . '$.fn.hoverClass = function(c){
	return this.each(function(){$(this).hover(function(){$(this).addClass(c);},function(){$(this).removeClass(c);});});
};
// ]]>
</script>' . "\n";
	echo $js;
}

// Enables localization, if applicable. 
load_theme_textdomain('textlog');

// Filters the Sandbox globalnav content
add_filter( 'globalnav_menu', 'textlog_globalnav' );

// Filters the default style sheet link
add_action( 'wp_head', 'textlog_css', 1 );

// Adds our function to print JavaScript via wp_footer()
add_action( 'wp_footer', 'textlog_js', 1 );
?>